package com.example.intentsharingdata;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch(item.getItemId()){
		case R.id.menu_text:
			//Share some text
			Intent textIntent = new Intent();
			//This intent should be directed only
			//at Activities that send data
			textIntent.setAction(Intent.ACTION_SEND);
			//Put the text into this intent
			textIntent.putExtra(Intent.EXTRA_TEXT, "This is some text");
			//This intent shares plain text
			textIntent.setType("text/plain");
			//Start the Activity, the system will
			//display a dialog to choose which application
			//to use
			startActivity(Intent.createChooser(textIntent,"Send with"));			
			return true;
		case R.id.menu_phone:
			Intent phoneIntent = new Intent();
			phoneIntent.setAction(Intent.ACTION_DIAL);
			//This intent uses Uri to parse a more human
			//readable command
			String phoneString = "tel:" + "888-555-2222";
			phoneIntent.setData(Uri.parse(phoneString));
			startActivity(Intent.createChooser(phoneIntent,"Dial with"));
			return true;
		case R.id.menu_url:
			Intent urlIntent = new Intent();
			urlIntent.setAction(Intent.ACTION_VIEW);
			//Uri can also parse URLs
			String urlString = "http://www.google.com";
			urlIntent.setData(Uri.parse(urlString));
			startActivity(Intent.createChooser(urlIntent,
						"Open with"));
			return true;
		}
		return false;
	}
	
	

}
